package TUILayer;
import java.util.Scanner;
import ControlLayer.*;

public class LoanUI
{
    private LoanCtr loanCtr;

    public LoanUI()
    {
        loanCtr = new LoanCtr();
    }

    public void start()
    {
        loanMenu();
    }

    public void loanMenu()
    {
        boolean exit = false;
        while(!exit) {
            int choice = writeLoanMenu();
            if(choice == 1) {
                loanCtr.createLoan(inputId(), inputDato(), inputPeriode());
            } else if(choice == 2) {
                loanCtr.addLoan(inputUserId(), inputLoanID());
            } else if(choice == 3) {
                loanCtr.deliverLoan(inputUserId(), inputLoanID());
            } else {
                exit = true;
            }
         
        }
    }


    public int writeLoanMenu()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** Loan Menu ***");
        System.out.println(" (1) Create Loan");
        System.out.println(" (2) Add Loan to person");
        System.out.println(" (3) Deliver Loan");
        System.out.println(" (4) Return");
        System.out.println("\n Make your choice: ");

        int choice = keyboard.nextInt();
        return choice;
    }
    
    public int inputId()
    {
        boolean ok = false;
        int id = 0;
        while(!ok)
        {
            Scanner keyboard = new Scanner(System.in);
            System.out.println(" Write id:  ");
            try {
                id = keyboard.nextInt();
                ok = true;
            } catch (Exception e) {
                System.out.println("You must enter a number - try again");
                String input = keyboard.nextLine();
        }
        }
        return id;
    }
    
    public String inputDato()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Write date: ");
        String dato = keyboard.nextLine();
        return dato;
    }
    
    public String inputPeriode()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Write loan time: ");
        String periode = keyboard.nextLine();
        return periode;
    }
    
    public int inputUserId() 
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Write userID: ");
        int userID = keyboard.nextInt();
        return userID;
    }
    
    public int inputLoanID()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Write loanID ");
        int loanID = keyboard.nextInt();
        return loanID;
    }
    
}